package com.app.core.adapter;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.specialtreasure.freightdepot.R;
import com.specialtreasure.freightdepot.adapter.GoodsInfoAdapter;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2017/8/24.
 * 通用的adapter
 */

public abstract class CommonAdapter<T> extends BaseAdapter {

    private List<T> list = new ArrayList<T>();

    protected FragmentActivity context;

    public CommonAdapter(FragmentActivity context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public T getItem(int position) {
        return list == null ? null : list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    public void clear() {
        this.list.clear();
        notifyDataSetChanged();
    }

    public void addAll(List<T> list) {
        if (list != null) {
            this.list.addAll(list);
            notifyDataSetChanged();
        }
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }
}
